from flask import Flask, render_template

# 导入数据文件
from database import books_dict

app = Flask(__name__)


@app.route('/')
def index():
    category = '全部'
    # 取出所有书
    books_data = [book for books in books_dict.values() for book in books]
    return render_template('book.html', **locals())


@app.route('/<string:category>/')
def show_books(category):
    # 列表推导式 取出该分类下每一本书
    # 输入错误分类 返回空列表
    books_data = [books for books in books_dict.get(category, [])]
    return render_template('book.html', **locals())


if __name__ == '__main__':
    app.run(host="127.0.0.7", port=80, debug=True)
